package com.ruoyi.qsng.service.impl;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.uuid.SnowFlakeUtil;
import com.ruoyi.qsng.domain.KClearinghouseComment;
import com.ruoyi.qsng.mapper.KClearinghouseCommentMapper;
import com.ruoyi.qsng.mapper.KClearinghouseCommentReplyMapper;
import com.ruoyi.qsng.service.IKClearinghouseCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

import java.util.List;

/**
 * 交流中心_评论Service业务层处理
 *
 * @author kanglou
 * @date 2023-06-07
 */
@Service
public class KClearinghouseCommentServiceImpl implements IKClearinghouseCommentService {
    @Autowired
    private KClearinghouseCommentMapper kClearinghouseCommentMapper;


    @Autowired
    private KClearinghouseCommentReplyMapper kClearinghouseCommentReplyMapper;


    /**
     * 查询交流中心_评论
     *
     * @param id 交流中心_评论主键
     * @return 交流中心_评论
     */
    @Override
    public KClearinghouseComment selectKClearinghouseCommentById(String id) {
        return kClearinghouseCommentMapper.selectKClearinghouseCommentById(id);
    }

    @Override
    public List<KClearinghouseComment> selectKClearinghouseCommentListForApp(KClearinghouseComment kClearinghouseComment) {
        List<KClearinghouseComment> kClearinghouseCommentList = kClearinghouseCommentMapper.selectKClearinghouseCommentListForApp(kClearinghouseComment);

//        //查询回复列表
//        for (KClearinghouseComment kClearinghouseComment1:kClearinghouseCommentList) {
//            KClearinghouseCommentReply  kClearinghouseCommentReply =new KClearinghouseCommentReply();
//            kClearinghouseCommentReply.setCommentId(Long.valueOf(kClearinghouseComment1.getId()));
//            List<KClearinghouseCommentReply>   kClearinghouseCommentReplyList    = kClearinghouseCommentReplyMapper.selectKClearinghouseCommentReplyList(kClearinghouseCommentReply);
//            kClearinghouseComment1.setKClearinghouseCommentReplies(kClearinghouseCommentReplyList);
//        }
        return kClearinghouseCommentList;
    }

    /**
     * 查询交流中心_评论列表
     *
     * @param kClearinghouseComment 交流中心_评论
     * @return 交流中心_评论
     */
    @Override
    public List<KClearinghouseComment> selectKClearinghouseCommentList(KClearinghouseComment kClearinghouseComment) {
        return kClearinghouseCommentMapper.selectKClearinghouseCommentList(kClearinghouseComment);
    }

    /**
     * 新增交流中心_评论
     *
     * @param kClearinghouseComment 交流中心_评论
     * @return 结果
     */
    @Override
    public int insertKClearinghouseComment(KClearinghouseComment kClearinghouseComment) {
        Assert.notNull(kClearinghouseComment.getClearinghouseId(), "获取帖子id失败！");
        Assert.notNull(kClearinghouseComment.getContent(), "获取内容失败！");
        Long userId = SecurityUtils.getLoginUser().getUser().getUserId();
        Assert.notNull(userId, "评论人id获取失败！");
        kClearinghouseComment.setPlId(String.valueOf(userId));
        kClearinghouseComment.setId(SnowFlakeUtil.getNextId());
        kClearinghouseComment.setCreateTime(DateUtils.getNowDate());
        return kClearinghouseCommentMapper.insertKClearinghouseComment(kClearinghouseComment);
    }

    /**
     * 修改交流中心_评论
     *
     * @param kClearinghouseComment 交流中心_评论
     * @return 结果
     */
    @Override
    public int updateKClearinghouseComment(KClearinghouseComment kClearinghouseComment) {
        kClearinghouseComment.setUpdateTime(DateUtils.getNowDate());
        return kClearinghouseCommentMapper.updateKClearinghouseComment(kClearinghouseComment);
    }

    /**
     * 批量删除交流中心_评论
     *
     * @param ids 需要删除的交流中心_评论主键
     * @return 结果
     */
    @Override
    public int deleteKClearinghouseCommentByIds(String[] ids) {
        return kClearinghouseCommentMapper.deleteKClearinghouseCommentByIds(ids);
    }

    /**
     * 删除交流中心_评论信息
     *
     * @param id 交流中心_评论主键
     * @return 结果
     */
    @Override
    public int deleteKClearinghouseCommentById(String id) {
        return kClearinghouseCommentMapper.deleteKClearinghouseCommentById(id);
    }
}
